﻿using MDT.LifeSewagePlatform.Conmmon;
using MDT.LifeSewagePlatform.Entity;
using MDT.LifeSewagePlatform.InterfaceService;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Linq;
using System.Threading.Tasks;

namespace MDT.LifeSewagePlatform.ServiceInstance.Controllers
{
    [Route("api/ruleCompany")]
    [ApiController]
    public class RuleCompanyController : BaseController
    {

        [Autowired]
        private IReuleCompanyService ruleCompanyService { set;get; }
        public RuleCompanyController()
        {

        }

        [HttpPost("{ruleId}/{companyId}")]
        public async Task<BaseMessage> AddAsync(int ruleId,int companyId)
        {
            return await ruleCompanyService.AddAsync(ruleId,companyId,GetUserID());
        }
        ///// <summary>
        ///// 
        ///// </summary>
        ///// <param name="ruleId"></param>
        ///// <param name="companyId"></param>
        ///// <returns></returns>
        //[HttpPost("{ruleIds}/{companyId}")]
        //public async Task<BaseMessage> AddAsync(string ruleIds, int companyId)
        //{
        //    int[] ids = null;
        //    if (ruleIds.Contains(','))
        //    {
        //     ids = (int[])ruleIds.Split(',').Select(t => { int val = 0; int.TryParse(t, out val); return val;});
        //    }


        //    return await ruleCompanyService.AddAsync(ids,companyId, GetUserID());
        //}
        /// <summary>
        /// 
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="ruleCompanyDto"></param>
        /// <returns></returns>
        [HttpPut("{Id}")]
        public async Task<BaseMessage> UpdateAsync(int Id,[FromForm]RuleCompanyUpdateDto ruleCompanyDto)
        {
            return await ruleCompanyService.UpdateAsync(Id,ruleCompanyDto,GetUserID());
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>

        [HttpDelete("{ID}")]

        public async Task<BaseMessage> DeleteAsync(int Id)
        {
            return await ruleCompanyService.DeleteAsync(Id);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpDelete("soft/{Id}")]
        public async Task<BaseMessage> SoftDeleteAsync(int Id)
        {
            return await ruleCompanyService.SoftDeleteAsync(Id, GetUserID());
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="Params"></param>
        /// <returns></returns>
        [HttpGet()]
        public async Task<BaseMessage> GetAsync([FromQuery]RuleCompanyParameter Params)
        {
            return await ruleCompanyService.GetRuleCompany(Params);
        }
    }
}
